package dp.gr03.payroll.application.commands;

import dp.gr03.payroll.exception.InvalidArgumentsException;
import dp.gr03.payroll.exception.PayRollException;
import dp.gr03.payroll.payrollApplication.Transaction;
import dp.gr03.payroll.transactionFactory.TransactionFactoryImplementation;

public class DeleteEmployeeCommand implements TransactionParser
{

    @Override
    public String getActionString()
    {
        return "DelEmp";
    }

    @Override
    public Transaction parse(String[] arguments) throws PayRollException
    {
        if (arguments.length == 2)
        {
            int employeeId = 0;
            try
            {
                employeeId = Integer.parseInt(arguments[1]);
            } catch (NumberFormatException e)
            {
                throw new PayRollException("Employee ID should be a number");
            }
            return TransactionFactoryImplementation.getInstance().makeDeleteEmployeeTransaction(employeeId);
        } else
        {
            throw new InvalidArgumentsException();
        }
    }

}
